package com.shop.controller;

import com.shop.constant.MessageConstant;
import com.shop.entity.Result;
import com.shop.pojo.OrderItem;
import com.shop.service.OrderItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orderitem")
@Api(tags = "订单详情管理")
public class OrderItemController {
    @Reference
    private OrderItemService orderItemService;

    @GetMapping("/add")
    @ApiOperation("添加订单详情接口")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "int",name = "gid",value = "商品id",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "oid",value = "订单id",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "uid",value = "用户id",required = true,example = "0"),@ApiImplicitParam(dataType = "int",name = "number",value = "购买数量",required = true,example = "0")})
    public Result add(@RequestParam(required = true) Integer gid,@RequestParam(required = true) Integer oid,@RequestParam(required = true) Integer uid,@RequestParam(required = true) Integer number){
        orderItemService.add(gid,oid,uid,number);
        return new Result(true, MessageConstant.ADD_SUCCESS);
    }

    @GetMapping("/findAll")
    @ApiOperation("显示全部订单详情接口")
    public Result findAll(@RequestParam(required = true)Integer id){
        List<OrderItem> list=orderItemService.findAll(id);
        return new Result(true,MessageConstant.QUERY_SUCCESS,list);
    }
}
